
#include "sdl_interface.h"
#include "v3d_renderer.h"

SdlInterface::SdlInterface(void)
{
	LOG("hello sdl_interface ......\n");

}

SdlInterface::~SdlInterface(void)
{
	SDL_Quit();

}


void SdlInterface::Update()
{
	V3dInterface::Update();
}

void SdlInterface::Start()
{
	if(RENDERER != NULL)
	{
		RENDERER->Resize(V3D_SCREEN_WIDTH, V3D_SCREEN_HEIGHT);
	}
	bool running = true;
    while( running )
    {
        SDL_Event event;
        while( SDL_PollEvent(&event) )
        {
            switch (event.type)
            {
            case SDL_QUIT:  
                running = false; 
                break;
            default:        
                break;
            }
        }

   		if(RENDERER != NULL)
			RENDERER->Update();    

        SDL_GL_SwapBuffers();

    }
}

void SdlInterface::InitWindow()
{
	if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) 
	{
		printf("ERROR: %s\n", SDL_GetError());
		return ;
	}
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	screen = SDL_SetVideoMode( V3D_SCREEN_WIDTH, V3D_SCREEN_HEIGHT, 16, SDL_OPENGL);

}




